home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7814 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: menkar.cs.utk.edu!doolin
  2. From: doolin@menkar.cs.utk.edu (David Doolin)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: GNU C & pow(x,y)
  5. Date: 28 Feb 1996 23:16:19 GMT
  6. Organization: Computer Science Dept, University of Tennessee, Knoxville
  7. Distribution: world
  8. Message-ID: <4h2no3INN2sm@CS.UTK.EDU>
  9. References: <9602162139036@br-ranch.org> <4gq1o5$386@SNFC21_SRVR_WWW.PBI.net>
  10. NNTP-Posting-Host: menkar.cs.utk.edu
  11.  
  12. In article <4gq1o5$386@SNFC21_SRVR_WWW.PBI.net>, mich@pbinet.com writes:
  13. |> In <9602162139036@br-ranch.org>, robert.threet@br-ranch.org (Robert Threet) writes:
  14. |> >I've tried using 1/x instead of the negative exponent, but I don't 
  15. |> >think that's my problem.  Here's the line:
  16. |> 
  17. |> >  paymnt = pow((amt * mo_rate)/(1-(1 + mo_rate)), (-mo_rate));
  18. |> 
  19. |> >All variables are defined as floating point.  I've included
  20. |> >"math.h" and I use this to compile:
  21. |> 
  22. |> >  gcc -o mort mort.c -lm
  23. |> 
  24. |> >Despite this I keep getting the error: "undefined ref. to pow".
  25. |> 
  26. |> >Can someone...
  27. |> 
  28. |> >A) Tell me what I'm doing wrong...  or
  29. |> >B) Give me a better formula for calculating a mortgage payment?
  30. |> 
  31. |> I don't think your formula is the problem. Don't you need to explicately name the
  32. |> object file on the command line for GCC? Also, you might make sure you're using
  33. |> function prototypes.
  34. |> 
  35.  
  36.  
  37. Yeah, yeah.  Look at the man page:
  38.  
  39.  
  40. EXP(3M)               MATHEMATICAL LIBRARY                EXP(3M)
  41.  
  42.  
  43.  
  44. NAME
  45.      exp, expm1, exp2, exp10, log, log1p, log2, log10, pow,  com-
  46.      pound, annuity - exponential, logarithm, power
  47.  
  48. SYNOPSIS
  49.      #include <math.h>
  50.  
  51. ...
  52.  
  53.  double pow(double x, double y);
  54.  ^^^^^^
  55. ...
  56.  
  57.  
  58. This silly stuff happens to me all the time.  
  59. ROT (rule of thumb):  If you use <math.h>, declare
  60. all would-be floats as doubles.  Unless your code 
  61. is way huge, or it consists of calling that routine
  62. ad infinitum, you probably won't notice the speed
  63. difference in execution over floats. 
  64.  
  65. Ciao,
  66. Dave Doolin
  67.